package com.zm.demo.core.leetcode;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;

/**
 * @author zoum
 * @create 2020/1/13 16:41
 */
public class ContainsNearbyDuplicate {

    public boolean containsNearbyDuplicate(int[] nums, int k) {

        if(nums == null || nums.length == 0){
            return false;
        }
        Queue<Integer> queue = new ArrayDeque<>();
        for (int i = 0; i < nums.length; i++) {
            if (queue.contains(nums[i])){
                return true;
            }

            queue.add(nums[i]);
            if (queue.size()>k){
                queue.poll();
            }
        }
        return false;
    }
}
